// Disable graphic
#ifdef NO_GRAPHIC
#define GRAPHIC_H
#endif

#ifndef GRAPHIC_H
#define GRAPHIC_H

#include <SDL2/SDL.h>
#include <SDL2/SDL_ttf.h>
#include <stdbool.h>
#include "defines.h"
#include "config.h"
#include "utils.h"

enum MouseMode {
    M_MOVE,
    M_DRAW,
    M_END,
};

enum DrawMode {
    DM_WALL,
    DM_DEL,
    DM_FOOD,
    DM_INFO,
    DM_PORTAL,
};

typedef unsigned Button;

struct Graphic {
    SDL_Renderer   *renderer;
    SDL_Window     *window;
    TTF_Font       *font;
    enum ColorMode colorType;
    bool           running;
    bool           renderActive;
    bool           pause;
    bool           showTPS;
    bool           mousedown;
    bool           shiftPressed;
    bool           oneStep;
    int            mouseX1, mouseY1;
    int            mouseX2, mouseY2;
    int            mouseX3, mouseY3;
    float          zoom;
    unsigned       mouseButton;
    SDL_Rect       viewport;
    float          viewportX, viewportY;
    enum MouseMode mouseMode;
    unsigned       width, height;
    enum DrawMode  mouseFunc[4];
};

typedef void (*ButtonFunc)(struct Graphic*, struct World*);
struct _Button {
    SDL_Color color;
    bool      active;
    char      text[9];
    ButtonFunc func;
};

struct Graphic *G_init(unsigned width, unsigned height, char* fontpath);
void G_close(struct Graphic *g);
void drawText(struct Graphic *g, char* text, SDL_Color color, int x, int y);
void mouseUpdate(struct World *w, struct Graphic *g);
int buttonToScreenY(Button button);
void keypress(struct World *w, struct Graphic *g);
void render(struct World *w, struct Graphic *g);
void worldToScreen(struct Graphic *g, int worldX, int worldY, int *screenX, int *screenY);
void screenToWorld(struct Graphic *g, int screenX, int screenY, int *worldX, int *worldY);
Button registerButton(struct Graphic *g, char text[], SDL_Color color, ButtonFunc pressFunc);
bool checkButton(struct Graphic *g, Button button);

#endif
